#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016-2018, Niklas Hauser
# Copyright (c) 2017, Fabian Greif
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

def init(module):
    module.name = ":board:nucleo-h743zi"
    module.description = """\
# NUCLEO-H743ZI

[Nucleo kit for STM32H743ZI](https://www.st.com/en/evaluation-tools/nucleo-h743zi.html)

Please note that this BSP uses the Y revision of the STM32H743, which limits the
main clock frequency to ≤400MHz and applies an errata bug fix to the SysTick,
whose reference clock cannot be divided by 8.

See the [STM32H743 errata sheet](https://www.st.com/resource/en/errata_sheet/es0392-stm32h742xig-and-stm32h743xig-device-limitations-stmicroelectronics.pdf).

In case you are using the new revision V of STM32H743, you can overwrite the
target option in your `project.xml`:

```xml
<library>
  <extends>modm:nucleo-h743zi</extends>
  <options>
    <option name="modm:target">stm32h743zit6/revV</option>
  </options>
</library>
```
"""

def prepare(module, options):
    if not options[":target"].partname.startswith("stm32h743zit"):
        return False

    module.depends(
        ":debug",
        ":architecture:clock",
        ":platform:core",
        ":platform:gpio",
        ":platform:clock",
        ":platform:uart:3",
        ":platform:usb:fs")

    return True

def build(env):
    env.outbasepath = "modm/src/modm/board"
    env.substitutions = {
        "with_logger": True,
        "with_assert": env.has_module(":architecture:assert")
    }
    env.template("../board.cpp.in", "board.cpp")
    env.copy('.')
    env.copy("../nucleo144_arduino.hpp", "nucleo144_arduino.hpp")
    env.collect(":build:openocd.source", "board/st_nucleo_h743zi.cfg");
